package model.semantics.infinary;

import model.RGBColor;
import model.semantics.InfinaryOperation;

/**
 * Find the minimum based on intensity.
 * 
 * @author Anne Weng
 */
public class Min extends InfinaryOperation 
{
	protected boolean leftAssociative = false;
	
	public Min(int precedence)
	{
		super(precedence);
	}
	
	@Override
    protected RGBColor evaluateColor (RGBColor[] colors)
    {
		double minimum = Double.MAX_VALUE;						//Initialize minimum
		RGBColor minColor = null;
        for (int i = 0; i < colors.length; i++)
        {
        	RGBColor current = colors[i];
        	double sum = current.getRed() + current.getBlue() + current.getGreen();
        	if (sum < minimum) {
        		minimum = 0 + sum;
        		minColor = colors[i];
        	}
        }
        return minColor;
    }
	
}
